<template>
  <page-header-wrapper :title="false">
    <a-alert message="！！！审核通过的合同，如果总打款金额有变动，需要重新提交审核" banner />
    <a-card :bordered="false" :style="{ marginTop: '25px', marginBottom: '25px' }">
      <a-steps :current="0">
        <a-step title="填写合同基本信息" />
        <a-step title="选择业务"/>
        <a-step title="上传纸质合同" />
        <a-step title="添加打款信息" />
        <a-step title="添加地址信息" />
        <a-step title="提交审核" />
      </a-steps>
    </a-card>
    <a-card title="添加合同" :loading="loading" :bordered="false">
      <div slot="extra">
        <a-button type="primary" size="small" ghost @click="$router.go(-1)">返回</a-button>
      </div>
      <!--        <a-alert :message="`合同编号：${contract}`" :description="`合同金额：1600.00(官费：800.00 | 代理费：800.00) (已打款金额：1600.00 | 剩余尾款：0.00)`" type="success" :style="{ marginBottom: '20px' }" />-->
      <a-tabs :tabBarGutter="10" :active-key="currentTabs" type="card" size="large">
        <a-tab-pane key="1" tab="基本信息"></a-tab-pane>
        <a-tab-pane key="2" tab="业务信息" disabled></a-tab-pane>
        <a-tab-pane key="3" tab="纸质合同" disabled></a-tab-pane>
        <a-tab-pane key="4" tab="打款信息" disabled></a-tab-pane>
        <a-tab-pane key="5" tab="地址信息" disabled></a-tab-pane>
        <a-tab-pane key="6" tab="审核历史" disabled></a-tab-pane>
        <a-tab-pane key="7" tab="转移记录" disabled></a-tab-pane>
      </a-tabs>
      <div class="contract_content">
        <Base :info="info" v-if="currentTabs == 1" @nextStep="onSubEdit"></Base>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import {
    Base
  } from './components'
  import { getAddInfo, saveAddInfo } from '@/api/contract'

  export default {
    components: {
      Base
    },
    name: 'ContractDetail',
    data () {
      return {
        queryParam: {
          customer_id: '',
          part: '1'
        },
        loading: true,
        customerId: '',
        currentTabs: '1',
        info: {}
      }
    },
    activated () {
      this.queryParam['customer_id'] = this.$route.query.customer_id
      this.init(this.queryParam)
    },
    methods: {
      init (params) {
        const app = this
        app.loading = true
        getAddInfo(params).then(res => {
          if (res.status === 0) {
            app.info = res.result.contract
            app.loading = false
          } else {
            app.$notification.error({
              message: '错误',
              description: '没有指定用户ID'
            })
            setTimeout(() => {
              app.$router.go(-1)
            }, 1000)
          }
        })
      },
      onSubEdit (part) {
        const { info } = this
        const form = {}
        form['customer_id'] = this.queryParam['customer_id']
        form['part'] = part
        form['contract[tm_name]'] = info.tm_name
        form['contract[subject]'] = info.subject
        form['contract[subject_id]'] = info.subject_id
        form['contract[customer_name]'] = info.customer_name
        form['contract[phone1]'] = info.phone1
        form['contract[phone2]'] = info.phone2
        form['contract[wechat]'] = info.wechat
        saveAddInfo(form).then(res => {
          if (res.status === 0) {
            this.$router.push({ name: 'ContractDetail', params: { cid: res.result.contract_id } })
          } else {
            this.$warning({
              title: res.msg
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
